<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link href="${ctx}/css/style.css" type="text/css" rel="stylesheet" /> 
    <link href="${ctx}/js/ztree/css/demo.css" type="text/css" rel="stylesheet">
    <link href="${ctx}/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
    <script src="${ctx}/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.cookie.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.core-3.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.excheck-3.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.exedit-3.3.min.js"></script>
  
    <title>安全系统—角色列表</title>
<body>
  <div class="m_right">
    
    <div class="m_r_tips">
     <div class="m_r_lefttips">您现在的位置：<a href="${ctx}/admin/home.jsp">首页</a>&gt;系统管理&gt;权限管理</div>
        <jsp:include page="/commons/admin/admin_login_remind.jsp"/>
    </div>
    
    
    <div class="m_r_list">
    </div>
    
    
    <div>
    	<h1>按esc键取消修改 修改完毕按enter 只能修改最底层节点 ajax更新 所见即所得</h1>
    </div>

    <div>
    <p>
       <!-- 保存修改前节点名称，用户操作失败恢复 -->
       <input type="hidden" value="" id="old_name"/>
	 [ <a id="expandAllBtn" href="#"  onclick="return false;">全部展开</a> ]&nbsp;&nbsp;&nbsp;&nbsp;
	 [ <a id="collapseAllBtn" href="#" onclick="return false;">全部折叠</a> ]&nbsp;&nbsp;&nbsp;&nbsp;<br/>
		&nbsp;&nbsp;&nbsp;&nbsp; 单个节点（包括子节点）&nbsp;&nbsp;&nbsp;&nbsp;<br/>
	 &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="expandSonBtn" href="#"  onclick="return false;">展开</a> ]&nbsp;&nbsp;&nbsp;&nbsp;
	 &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="collapseSonBtn" href="#"  onclick="return false;">折叠</a> ]
	 
	 </p>
    </div>
    <div class="zTreeDemoBackground left fl" style="width:800px">
        <ul id="permTree" class="ztree" style="width:700px"></ul>
    </div>
    <div class="zTreeDemoBackground left fl" style="width:600px;height: auto;">
        <div>
    <h1>权限编码</h1>    
    <ul>
    	<li>中括号[]内的为权限编码。改动发布之后就不能变动</li>
    	<li>eg 系统管理-查看账号列表[SYS:BIZ:VIEW]</li>
    </ul>          
    <h1>模块分隔符</h1>    
    <ul>
    	<li>英文冒号  :</li>
    </ul>    
    <h1>缩写说明</h1>    
    <ul>
    	<li>业务business  BIZ</li>
    	<li>管理manage MGE</li>
    	<li>业务管理(business manage) BIZ_MGE</li>
    </ul>    
    <h1>模块</h1>
    <ul>
    	<li>系统管理 SYS</li>
    	<li>我的信息 MYINFO</li>
    </ul>
    <h1>操作</h1>    
    <ul>
    	<li>查看 VIEW</li>
    	<li>增加 ADD</li>
    	<li>审核 AUDIT</li>
    	<li>删除 DEL</li>
    	<li>修改 MOD</li>
    	<li>申请 APPLY</li>
    	<li>撤销 CANCEl</li>
    	<li>导出 EXPORT</li>
    	<li>查询 QUERY</li>
    </ul>

    </div>
    </div>
    <!-- role id hidden -->
    
   
</div>
</body>
  <SCRIPT type="text/javascript">
        <!--
        var setting = {
			edit: {
				enable: true,
				showRenameBtn : true,
				showRemoveBtn: false,
				renameTitle: "编辑节点名称"
			},
            check: {
                enable: false
//                chkboxType: { "Y" : "", "N" : "" }
            },  
            data: {
                 simpleData: {
                     enable: true
                 }
            },
            /**
            async: {
                enable: true,
                url:"async.jsp",
                autoParam:["id", "name", "level=lv"],
                otherParam:{"otherParam":"zTreeAsyncTest"},
                dataFilter: filter
            },        **/
            callback:{
                  /*   onClick:function(event, treeId, treeNode, clickFlag){ 
                    	if(!treeNode.isParent) 
                    		alert(treeNode.id + " " 
                    				+ treeId + " "
                    				+ treeNode.name + " "
                    				+ treeNode.value + " " 
                    				+ treeNode.chkDisabled + " " 
                    				+ treeNode.checked);
                    	},  */
                    beforeRename : zTreeBeforeRename ,
                    onRename: zTreeOnRename
                    //onCheck: function(event, treeId, treeNode){if(!treeNode.isParent)  alert(treeId + " " +treeNode.value  + " " + treeNode.pId);},
                    //beforeExpand: beforeExpand,
                    //onExpand: onExpand
             }
        };

       var treeData = '${menTree}';      
       var zNodes = eval('('+treeData+')');

        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
            }
            return childNodes;
        }
        
        
        function zTreeBeforeRename(treeId, treeNode, newName) {
        	if (treeNode.isParent) {
        		alert("只能修改最底层节点 按esc键取消修改");
        	}
        	if (!treeNode.isParent && $.trim(newName) != "" && $.trim(treeNode.name) != newName) {
        		$("#old_name").val(treeNode.name);
        		return true;
        	} else {
        		return false;
        	}
        	
        }
        
        function zTreeOnRename(event, treeId, treeNode) {
        	if (treeNode.isParent) {
        		return;
        	}
        	var oauthId = treeNode.id;
        	if (oauthId.indexOf("o_") != -1) {
        		oauthId = oauthId.substring(2);
        	}
        	$.post("${ctx}/admin/role/updateOAuth.do", 
    		    {
        		  "oauth.oauthId" : oauthId,
        		  "oauth.oauthName" : treeNode.name
        		},
        		function(data){
        		     if (data != "ok") {
        		    	 treeNode.name  = $("#old_name").val();
        		    	 $("#old_name").val("");
        		    	 var treeObj = $.fn.zTree.getZTreeObj("permTree");
        		    	 treeObj.updateNode(treeNode);
        		    	 alert(data + "编码不能重复");
        		     } 	  
                 }
        	);
        }
        
        var curExpandNode = null;
        function beforeExpand(treeId, treeNode) {
            var pNode = curExpandNode ? curExpandNode.getParentNode():null;
            var treeNodeP = treeNode.parentTId ? treeNode.getParentNode():null;
            var zTree = $.fn.zTree.getZTreeObj("permTree");
            for(var i=0, l=!treeNodeP ? 0:treeNodeP.children.length; i<l; i++ ) {
                if (treeNode !== treeNodeP.children[i]) {
                    zTree.expandNode(treeNodeP.children[i], false);
                }
            }
            while (pNode) {
                if (pNode === treeNode) {
                    break;
                }
                pNode = pNode.getParentNode();
            }
            if (!pNode) {
                singlePath(treeNode);
            }

        }
        function singlePath(newNode) {
            if (newNode === curExpandNode) return;
            if (curExpandNode && curExpandNode.open==true) {
                var zTree = $.fn.zTree.getZTreeObj("permTree");
                if (newNode.parentTId === curExpandNode.parentTId) {
                    zTree.expandNode(curExpandNode, false);
                } else {
                    var newParents = [];
                    while (newNode) {
                        newNode = newNode.getParentNode();
                        if (newNode === curExpandNode) {
                            newParents = null;
                            break;
                        } else if (newNode) {
                            newParents.push(newNode);
                        }
                    }
                    if (newParents!=null) {
                        var oldNode = curExpandNode;
                        var oldParents = [];
                        while (oldNode) {
                            oldNode = oldNode.getParentNode();
                            if (oldNode) {
                                oldParents.push(oldNode);
                            }
                        }
                        if (newParents.length>0) {
                            for (var i = Math.min(newParents.length, oldParents.length)-1; i>=0; i--) {
                                if (newParents[i] !== oldParents[i]) {
                                    zTree.expandNode(oldParents[i], false);
                                    break;
                                }
                            }
                        } else {
                            zTree.expandNode(oldParents[oldParents.length-1], false);
                        }
                    }
                }
            }
            curExpandNode = newNode;
        }

        function onExpand(event, treeId, treeNode) {
            curExpandNode = treeNode;
        }

       $.fn.zTree.init($("#permTree"), setting,zNodes);
       $("#expandAllBtn").bind("click", {type:"expandAll"}, expandNode);
	   $("#collapseAllBtn").bind("click", {type:"collapseAll"}, expandNode);        
		$("#expandSonBtn").bind("click", {type:"expandSon"}, expandNode);
		$("#collapseSonBtn").bind("click", {type:"collapseSon"}, expandNode); 
	   
		function expandNode(e) {
			var zTree = $.fn.zTree.getZTreeObj("permTree"),
			type = e.data.type,
			nodes = zTree.getSelectedNodes();
			if (type.indexOf("All")<0 && nodes.length == 0) {
				alert("请先选择一个父节点");
			}

			if (type == "expandAll") {
				zTree.expandAll(true);
			} else if (type == "collapseAll") {
				zTree.expandAll(false);
			} else {
				var callbackFlag = $("#callbackTrigger").attr("checked");
				for (var i=0, l=nodes.length; i<l; i++) {
					zTree.setting.view.fontCss = {};
					if (type == "expand") {
						zTree.expandNode(nodes[i], true, null, null, callbackFlag);
					} else if (type == "collapse") {
						zTree.expandNode(nodes[i], false, null, null, callbackFlag);
					} else if (type == "toggle") {
						zTree.expandNode(nodes[i], null, null, null, callbackFlag);
					} else if (type == "expandSon") {
						zTree.expandNode(nodes[i], true, true, null, callbackFlag);
					} else if (type == "collapseSon") {
						zTree.expandNode(nodes[i], false, true, null, callbackFlag);
					}
				}
			}
		}
        
        //-->
    </SCRIPT>
</html>
